package com.banyuan.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/success")
public class SuccessServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       resp.setCharacterEncoding("utf-8");
       resp.setContentType("text/html;utf-8");
        String phoneNum = req.getParameter("phoneNum");
        String nextRandom = req.getParameter("random");
        HttpSession session = req.getSession();
        String random = String.valueOf(session.getAttribute(phoneNum));
        if (random.equals(nextRandom)) {
            resp.getWriter().write("log success");
        } else {
             resp.getWriter().write("final <a href=\"/web05/denglu.html\">点击重新登录</a>\n");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
